const parmas = {
    name: '张三',
    age: 18,
    sex: '男'
}
console.log(`${parmas.name}的年龄是${parmas.age}，性别是${parmas.sex}`);

let a: unknown
a = 100
a = true
a = '123'

let b: string
// b = a as string // 断言
b = <string>a // 断言
console.log('a===', a);
console.log('b===', b);

function f1(hello: string): void {
    console.log('哈哈哈')
}
let f1Res = f1('hello');
console.log('f1===', f1Res)

let user: {
    name: string;
    age: number;
    [key: string]: any; // 索引签名(除了name和age外，可以有任何一个key，key是字符串就可，并且key的值是any类型)
}
user = { name: '张三', age: 18, sex: '男', height: 1.88 };
console.log('object===', user)

let obj1: string[]; // 字符串数组
let obj2: Array<string>; // 字符串数组(泛型)
obj1 = ['123', '456']
obj2 = ['123', '456']
console.log('字符串数组===', obj1)
console.log('字符串素组===泛型', obj2)

let arr1: [string, number]; // 元组(固定长度的数组)
let arr2: [number, ...string[]] // 可以有任意多个string类型的值
arr1 = ['123', 123]
arr2 = [1000, '123', '456']
console.log('tuple===', arr1);
console.log('tuple===', arr2);
const enum Direction {
    Up,
    Down,
    Left,
    Right
}

function f3(str: Direction) {
    if (str === Direction.Up) {
        console.log('emum===枚举===向上')
    } else if (str === Direction.Down) {
        console.log('emum===枚举===向下')
    }
}
f3(Direction.Up);
f3(Direction.Down);

type status = number | string // 类型别名(可以是number或string)
type sex = '男' | '女' // 联合类型(只能是男或女)

function f4(str: status): void {
    console.log('type===', str)
}
function f5(str: sex): void {
    console.log('type===', str)
}
f4(200);
f4('404');
f5('男');
f5('女');

type Width = {
    width: number
}
type Height = {
    height: number
    border: string
}

type Div = Width & Height // 交叉类型(必须有width和height)

const div: Div = {
    width: 100,
    height: 200,
    border: '1px solid #000'
}
